package com.qhhc.dtomapper;

import ch.qos.logback.core.util.StringUtil;
import com.qhhc.dto.CarAppointmentDto;
import com.qhhc.entity.CarAppointment;
import com.qhhc.enums.Status;
import com.qhhc.vo.CarAppointmentVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

@Mapper
public interface CarAppointmentMapperDto {
    CarAppointmentMapperDto INSTANCE = Mappers.getMapper(CarAppointmentMapperDto.class);

     @Mapping(target = "status", expression = "java(mapStatus(entity))")
     CarAppointmentDto  toDto(CarAppointment entity);

    default String mapStatus(CarAppointment entity) {
       String statusValue = entity.getStatus();
        System.out.println("这是一个数据库产出来的状态值:"+statusValue);
//        String statusValue = entity.getStatus();
        if(!StringUtil.isNullOrEmpty(statusValue)) {

            return Status.fromValue(statusValue).toString();
        }else {
            return "pending";
        }
    }

    @Mapping(target = "status", expression = "java(reverseMapStatus(vo))")
    CarAppointment  toEntity(CarAppointmentVo vo);
    default String reverseMapStatus(CarAppointmentVo vo) {
        String statusValue = vo.getStatus();
        System.out.println("这是一个数据库产出来的状态值:"+statusValue);
//        String statusValue = entity.getStatus();
        if(!StringUtil.isNullOrEmpty(statusValue)) {
            return Status.fromDescription(statusValue).getValue().toString();
        }else {
            return "0";
        }
    }
}
